<?php
print_r($_POST);
//	ADD USER INFORMATION
function checkExist()
{
}
if(isset($_POST[cmdSubmitAddDevice]) && $_POST[cmdSubmitAddDevice]!='')
{
	$txtDeviceName = str_replace(" ","_",$_POST[txtDeviceName]);

	/*$sql = "SELECT * FROM tb_deviceinfo WHERE di_clientId = ".$_SESSION[clientID]." AND di_deviceId = '".$txtDeviceName."'";
	$rows = $db->query($sql);
	if($db->affected_rows)
	{
		header("location:?ch=status&au=3&msg=0");
		exit;
	}
	else*/ $data['di_deviceId'] = $txtDeviceName;


	/*$sql = "SELECT * FROM tb_deviceinfo WHERE di_clientId = ".$_SESSION[clientID]." AND di_imeiId = '".$_POST[txtImeiNo]."'";
	$rows = $db->query($sql);
	if($db->affected_rows)
	{
		header("location:?ch=status&au=3&msg=0");
		exit;
	}
	else*/ $data['di_imeiId'] = $_POST[txtImeiNo];
	
	/*$sql = "SELECT * FROM tb_deviceinfo WHERE di_clientId = ".$_SESSION[clientID]." AND di_mobileNo = '".$_POST[txtMobileNo]."'";
	$rows = $db->query($sql);
	exit;
	if($db->affected_rows)
	{
		header("location:?ch=status&au=3&msg=0");
		exit;
	}
	else*/ $data['di_mobileNo'] = $_POST[txtMobileNo];

$data['di_odoMeter'] = $_POST[txtOdometer];
$data['di_deviceModel'] = $_POST[txtDeviceModel];
$data['di_userId'] = $_SESSION[userID];
$data['di_clientId'] = $_SESSION[clientID];

if($_POST[txtStatus])
	$data['di_status'] = $_POST[txtStatus];
else
	$data['di_status'] = 0;	

print_r($data);
exit;

if($db->query_insert("tb_deviceinfo", $data))
	$res = 1;
else $res = 0;

header("location:?ch=status&au=3&msg=".$res);
exit;

}


//		UPDATE USER INFORMATION
if(isset($_POST[cmdSubmitUpdateDevice]) && $_POST[cmdSubmitUpdateDevice]!='')
{
	$txtDeviceName = str_replace(" ","_",$_POST[txtDeviceName]);

	/*$sql = "SELECT * FROM tb_deviceinfo WHERE di_clientId = ".$_SESSION[clientID]." AND di_deviceId = '".$txtDeviceName."'";
	$rows = $db->query($sql);
	if($db->affected_rows)
	{
		header("location:?ch=status&au=3&msg=0");
		exit;
	}
	else*/ $data['di_deviceId'] = $txtDeviceName;


	/*$sql = "SELECT * FROM tb_deviceinfo WHERE di_clientId = ".$_SESSION[clientID]." AND di_imeiId = '".$_POST[txtImeiNo]."'";
	$rows = $db->query($sql);
	if($db->affected_rows)
	{
		header("location:?ch=status&au=3&msg=0");
		exit;
	}
	else*/ $data['di_imeiId'] = $_POST[txtImeiNo];
	
	/*$sql = "SELECT * FROM tb_deviceinfo WHERE di_clientId = ".$_SESSION[clientID]." AND di_mobileNo = '".$_POST[txtMobileNo]."'";
	$rows = $db->query($sql);
	exit;
	if($db->affected_rows)
	{
		header("location:?ch=status&au=3&msg=0");
		exit;
	}
	else*/ $data['di_mobileNo'] = $_POST[txtMobileNo];
	$data['di_odoMeter'] = $_POST[txtOdometer];
	$data['di_deviceModel'] = $_POST[txtDeviceModel];
	$data['di_updateDate'] = "NOW()";

if($_POST[txtStatus])
	$data['di_status'] = $_POST[txtStatus];
else
	$data['di_status'] = 0;	

//print_r($data);
//exit;

if($db->query_update("tb_deviceinfo", $data , "di_id=".$_POST[txtDeviceId]))
	$res = 1;
else $res = 0;

header("location:?ch=status&au=4&msg=".$res);
exit;

}


if(isset($_POST[cmdSubmitClientAddDevice]) && $_POST[cmdSubmitClientAddDevice]!='')
{
	$txtDeviceName = str_replace(" ","_",$_POST[txtDeviceName]);
	$data['di_deviceId'] = $txtDeviceName;
	$data['di_imeiId'] = $_POST[txtImeiNo];
	$data['di_mobileNo'] = $_POST[txtMobileNo];

	$data['di_odoMeter'] = $_POST[txtOdometer];
	$data['di_deviceModel'] = $_POST[txtDeviceModel];
	$data['di_userId'] = $_POST[txtClientUserId];
	$data['di_clientId'] = $_POST[txtClientId];

if($_POST[txtStatus])
	$data['di_status'] = $_POST[txtStatus];
else
	$data['di_status'] = 0;	

//print_r($data);
//exit;

if($db->query_insert("tb_deviceinfo", $data))
	$res = 1;
else $res = 0;

header("location:?ch=status&au=12&msg=".$res);
exit;

}

//		UPDATE USER INFORMATION
if(isset($_POST[cmdSubmitClientUpdateDevice]) && $_POST[cmdSubmitClientUpdateDevice]!='')
{
	$data['di_mobileNo'] = $_POST[txtMobileNo];	
	$data['di_odoMeter'] = $_POST[txtOdometer];
	$data['di_deviceModel'] = $_POST[txtDeviceModel];
	
	$data['di_userId'] = $_POST[txtClientUserId];
	$data['di_clientId'] = $_POST[txtClientId];
	$data['di_updateDate'] = "NOW()";
	

if($_POST[txtStatus])
	$data['di_status'] = $_POST[txtStatus];
else
	$data['di_status'] = 0;	

//print_r($data);
//exit;

if($db->query_update("tb_deviceinfo", $data , "di_id=".$_POST[txtDeviceId]))
	$res = 1;
else $res = 0;

header("location:?ch=status&au=13&msg=".$res);
exit;

}

if(isset($_POST[cmdAddModel]) && $_POST[cmdAddModel] !='')
{
	$cdata["model"] = $_POST[txtDevModelName];
	$cdata["tdm_manuName"] = $_POST[txtDevManuName];
	$cdata["tdm_aliasName"] = $_POST[txtDevAliasName];
	$cdata["tdm_noofInputs"] = $_POST[selDigitIn];
	$cdata["tdm_noofOutputs"] = $_POST[selDigitOut];
	$cdata["tdm_noofAnalog"] = $_POST[selAnalogIO];
	$cdata["tdm_immobFunc"] = $_POST[txtChkImmobFunc];

	if($_POST[txtChkImmobFunc] == 1)
	{
		$cdata["tdm_smsOnCode"] = $_POST[txtOnSMS];
		$cdata["tdm_smsOffCode"] = $_POST[txtOffSMS];
	}
	else
	{
		$cdata["tdm_smsOnCode"] = "";
		$cdata["tdm_smsOffCode"] = "";
	}
	
	print_r($cdata);
	//exit;
	
	if($db->query_insert("tb_device_model", $cdata))
		$res = 1;
	else $res = 0;
	
	header("location:?ch=status&au=18&msg=".$res);
	exit;
}

if(isset($_POST[cmdUpdateModel]) && $_POST[cmdUpdateModel] !='')
{
	$cdata["model"] = $_POST[txtDevModelName];
	$cdata["tdm_manuName"] = $_POST[txtDevManuName];
	$cdata["tdm_aliasName"] = $_POST[txtDevAliasName];
	$cdata["tdm_noofInputs"] = $_POST[selDigitIn];
	$cdata["tdm_noofOutputs"] = $_POST[selDigitOut];
	$cdata["tdm_noofAnalog"] = $_POST[selAnalogIO];
	$cdata["tdm_immobFunc"] = $_POST[txtChkImmobFunc];

	if($_POST[txtChkImmobFunc] == 1)
	{
		$cdata["tdm_smsOnCode"] = $_POST[txtOnSMS];
		$cdata["tdm_smsOffCode"] = $_POST[txtOffSMS];
	}
	else
	{
		$cdata["tdm_smsOnCode"] = "";
		$cdata["tdm_smsOffCode"] = "";
	}	
	$cdata["tdm_updateDate"] = 'NOW()';
	print_r($cdata);
	//exit;
	
	if($db->query_update("tb_device_model", $cdata, "id = ".$_POST[txtContId]))
		$res = 1;
	else $res = 0;
	
	header("location:?ch=status&au=19&msg=".$res);
	exit;
}

?>